<?php 
namespace app\common\model;
class Goods extends Common{
	protected $insert = ['addtime'=>SYS_TIME];
	protected function getStatusnameAttr($value,$data){
		return $data['status'] ? '开启' : '关闭';
	}
	protected function getThumbAttr($value){
		if(strpos($value,"http://") !== false){
			return $value;
		}
		else{
			return $value ? rtrim(APP_URL,"/").'/'.$value : '';
		}
	}
	protected function getCatnameAttr($value, $data){
		return db("GoodsCate")->where('id', $data['catid'])->value('title');
	}
	protected function getLinkurlAttr($value, $data){
		return APP_URL.'/index/goods/detail/id/'.$data['id'];
	}
	public function list_datas($data){
		$page = isset($data['page']) && $data['page'] ? $data['page'] : 1;
		$order = isset($data['order']) && $data['order'] ? $data['order'] : 'synth';
		switch ($order) {
			case 'synth':
				$order = "sale_nums desc, price desc";
				break;
			case 'market_inc':
				$order = "sale_nums asc";
				break;
			case 'market_dec':
				$order = "sale_nums desc";
				break;
			case 'price_inc':
				$order = "price asc";
				break;
			case 'price_dec':
				$order = "price desc";
				break;
		}
		$list = $this->where('catid', $data['catid'])->field('id, title, thumb, price, description, linkurl')->limit(($page-1)*30, 30)->order($order)->select();
		$lists = [];
		foreach ($list as $v) {
			$v['isfav'] = 0;
			$lists[] = $v;
		}
		return $lists;
	}
}